package ework;

import java.util.HashMap;
import java.util.Map;

public final class Main {
    private static Long interval = 30000L;
    private static String filename;
    private static final Map<String, String> paramMap = new HashMap<>();

    static {
        paramMap.put("-h", String.format("%-30s%-30s", "-i <interval>", "指定定时截图的间隔(毫秒), 默认值为30000") + "\n" +
                String.format("%-30s%-30s", "-n <filename>", "指定截图文件名，默认文件名为时间戳") + "\n" +
                String.format("%-30s%-30s", "-c", "取色器") + "\n");
    }

    public static void main(String[] args) {
        for (int i = 0; i < args.length; i++) {
            // 处理特殊参数
            if ("-i".equals(args[i]) && i <= args.length - 2) {
                try {
                    interval = Long.valueOf(args[i + 1]);
                } catch (NumberFormatException e) {
                    System.out.println("警告: " + args[i + 1] + "不是数值");
                    return;
                }
            } else if ("-n".equals(args[i]) && i <= args.length - 2) {
                filename = args[i + 1];
            } else if ("-c".equals(args[i])) {
                ColorDetector.run();
                return;
            } else if (paramMap.containsKey(args[i])) { // 处理通用参数
                System.out.println(paramMap.get(args[i]));
                return;
            }
        }
        ScreenCapture.run(interval, filename);
    }
}